import Vue from 'vue'
const elementUiCDataOrMethod = {
  data() {
    var validatePass = (rule, value, callback) => {
      // mixins {field: "desc", fullField: "desc", type: "string", validator: ƒ}
      console.log('mixins', rule, value)
      if (value === '') {
        callback(new Error('请输入密码'))
      } else {
        // if (this.ruleForm.checkPass !== '') {
        //   this.$refs.ruleForm.validateField('checkPass')
        // }
        callback()
      }
    }
    return {
      tableMixinData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄',
        id: 1,
        status: 1
      }, {
        date: '2016-05-03',
        name: '王小虎1',
        address: '上海市普陀区金沙江路 1518 弄1',
        status: 1,
        id: 2
      }],
      tableLoading: false,
      /* 分页*/
      pageNum: 1,
      pageSize: 10,
      pageTotal: 100,
      /* 表单*/
      formModel: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      fromRules: {
        isNotNull: [
          { required: true, message: '该字段不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { validator: validatePass, trigger: 'blur' }
        ]
      },
      /* 循环的表单*/
      forFormRules: {
        name: [{
          required: true,
          message: '请输入名称',
          trigger: 'blur' }],
        phone: [{
          required: true,
          message: '请输入账号手机号',
          trigger: 'blur' }],
        username: [{
          required: true,
          message: '请输入账号名称',
          trigger: 'blur' }],
        password: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur' }
        ]
      }, // 添加校验
      forFormModal: {
        name: '',
        userList: [{
          phone: '',
          username: '',
          password: ''
        }]
      },
      /* modal部分*/
      modalTitle: 'fai',
      dialogVisible: false,
      /* 时间日期*/
      dateTimeRangeModal: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
      datePickerOptions: {
        disabledDate: time => {
          return time.getTime() < Date.now() - 86400000
        },
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      /* 树*/
      treeData: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1',
          children: [{
            id: 9,
            label: '三级 1-1-1'
          }, {
            id: 10,
            label: '三级 1-1-2'
          }]
        }]
      }, {
        id: 2,
        label: '一级 2',
        children: [{
          id: 5,
          label: '二级 2-1'
        }, {
          id: 6,
          label: '二级 2-2'
        }]
      }, {
        id: 3,
        label: '一级 3',
        children: [{
          id: 7,
          label: '二级 3-1'
        }, {
          id: 8,
          label: '二级 3-2'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  computed: {
    // ...mapState('user', ['token', 'userInfo'])
  },
  watch: {

  },
  created() {

  },
  mounted() {

  },
  methods: {
    /* table*/
    tableHandleCheckClick(row) {
      console.log('mixins的handleCheckClick', row)
    },
    tableHandleEditClick(row) {
      console.log('mixins的handleCheckClick', row)
    },
    tableHandleDeleteClick(row) {
      console.log('mixins的handleCheckClick', row)
    },
    tableSingleCheckSelect(rows, row) {
      // const selected = rows.length && rows.indexOf(row) !== -1
      // if (selected) {
      //   this.vinArr.push(row.id)
      // } else {
      //   // 取消勾选
      //   this.vinArr.splice(this.vinArr.findIndex(item => item === row.id), 1)
      // }
    },
    /* 获取选中的行*/
    getCheckColumn() {
      console.log('checkColumn')
      console.log(this.$refs.refElTable.selection)
    },
    /* 设置选中的行*/
    setCheckColumn() {
      console.log('setCheckColumn')
      this.$refs['refElTable'].toggleRowSelection({
        date: '2016-05-03',
        name: '王小虎1',
        address: '上海市普陀区金沙江路 1518 弄1',
        status: 1,
        id: 2
      }, true)
    },
    clearSelection() {
      console.log('clearSelection')
      this.$refs.refElTable.clearSelection()
    },
    setCurrentRow() {
      console.log('setCurrentRow')
      this.$refs.refElTable.setCurrentRow()
    },
    /* 数据行*/
    select(selection, row) {
      console.log('select', selection, row)
    },
    /* 全选时触发*/
    selectAll(selection) {
      console.log('selectAll', selection)
    },
    /* 任何时候都会触发*/
    selectChange(selection) {
      console.log('selectChange', selection)
    },
    /* 分页*/
    pageHandleSizeChange(val) {
      console.log(`mixins pageHandleSizeChange: ${val}`)
      // this.pageSize = val
      // this.vehicleListReq()
    },
    pageHandleCurrentChange(val) {
      console.log(`mixins pageHandleCurrentChange: ${val}`)
      // this.pageNum = val
      // this.vehicleListReq()
    },
    /* 底部btn*/
    saveBtnClick() {
      console.log(`mixins saveBtnClick`)
    },
    /* form表单*/
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },
    /* modal部分*/
    beforeCloseModal() {
      this.dialogVisible = false
      console.log('mixins beforeCloseModal')
    },

    /* 通知*/
    elMessage(message, type, duration) {
      type = type || 'success'
      this.$message({
        showClose: true,
        message: message || '成功',
        type: type,
        center: false
      })
    },
    /* 提示*/
    elNotify(message, type, title, duration) {
      type = type || 'success'
      this.$notify[type]({
        title: title || '请传入标题',
        message: message || '请传入提示消息',
        position: 'top-right',
        duration: duration || 2500,
        offset: 40
      })
    },
    /* 确定*/
    elConfirm(title, message) {
      return new Promise((resolve, reject) => {
        this.$confirm(message || '你确定要删除吗', title || '确认框', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          resolve('OK')
        }).catch(() => {
          reject()
        })
      })
    },
    /* 通知*/
    message() {
      this.$message({
        showClose: true,
        message: '错了哦，这是一条错误消息',
        type: 'error',
        center: false
      })
    },
    confirm() {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    notify() {
      this.$notify.error({
        title: '错误',
        message: '这是一条错误的提示消息',
        position: 'top-right',
        duration: 2000,
        offset: 40
      })
    },
    /* tree*/
    /* 事件*/
    nodeContextmenu(data, node, row, rows) {
      console.log('nodeContextmenu')
      console.log(data, node, row, rows)
    },
    /* 子节点变化就触发一次*/
    checkChange(data, node, row) {
      console.log('checkChange')
      console.log(data, node, row)
    },
    /* 推荐使用这个*/
    check(halfCheckedNodes, halfCheckedKeys) {
      console.log('check')
      console.log(halfCheckedKeys, halfCheckedNodes)
    },
    /* 点击lable时触发以下操作*/
    nodeClick(data, node, row) {
      console.log('nodeClick')
      console.log(data, node, row)
    },
    currentChange(halfCheckedNodes, halfCheckedKeys) {
      console.log('currentChange')
      console.log(halfCheckedKeys, halfCheckedNodes)
    },
    updateKeyChildren() {
      console.log('updateKeyChildren')
      this.$refs.elTree.updateKeyChildren([7], [{
        id: 7,
        label: '二级 88888888-1'
      }])
    },

    getCheckedNodes() {
      console.log('getCheckedNodes', this.$refs.elTree.getCheckedNodes(true))
    },
    setCheckedNodes() {
      console.log('setCheckedNodes')
      this.$refs.elTree.setCheckedNodes([{
        id: 7,
        label: '二级 3-1',
        age: '1'
      }, {
        id: 8,
        label: '二级 3-2'
      }])
    },
    getCheckedKeys() {
      console.log('getCheckedKeys')
      console.log(this.$refs.elTree.getCheckedKeys(true))
    },
    setCheckedKeys() {
      console.log('setCheckedKeys')
      this.$refs.elTree.setCheckedKeys([1])
    },

    /* 用于选中父节点但是不想选中子节点*/
    setChecked() {
      console.log('setChecked')
      this.$refs.elTree.setChecked(1, true, true)
    },
    getHalfCheckedNodes() {
      console.log('getHalfCheckedNodes')
      console.log(this.$refs.elTree.getHalfCheckedNodes())
    },
    getHalfCheckedKeys() {
      console.log('getHalfCheckedKeys')
      console.log(this.$refs.elTree.getHalfCheckedKeys())
    },

    /* current 你当前选中的节点 */
    getCurrentNode() {
      console.log('getCurrentNode')
      console.log(this.$refs.elTree.getCurrentNode())
    },
    getCurrentKey() {
      console.log('getCurrentKey')
      console.log(this.$refs.elTree.getCurrentKey())
    },
    /* 不选中节点*/
    setCurrentKey() {
      console.log('setCurrentKey')
      this.$refs.elTree.setCurrentKey(8)
    },
    setCurrentNode() {
      console.log('setCurrentNode')
      this.$refs.elTree.setCurrentNode()
    },
    /* 获取node节点信息只能拿一个*/
    getNode() {
      console.log('getNode')
      console.log(this.$refs.elTree.getNode(1))
    },
    remove() {
      console.log('remove')
      this.$refs.elTree.remove(1)
    },
    /* 父添加子节点*/
    append() {
      console.log('append')
      this.$refs.elTree.append({
        id: 12,
        label: '666666'
      }, 1)
    },
    /* 节点节点添加 */
    insertBefore() {
      console.log('insertBefore')
      this.$refs.elTree.insertBefore({
        id: 12,
        label: '666666'
      }, 7)
    },
    /* 节点节点添加 */
    insertAfter() {
      console.log('insertAfter')
      this.$refs.elTree.insertAfter({
        id: 13,
        label: '888888'
      }, 7)
    }
  }
}

export default elementUiCDataOrMethod
